package com.spring.annoation;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

import com.spring.remote.Invoke;
import com.spring.remote.ModeView;

public class AnnoationInit {

	public static Map<String, Invoke> parseMethod(Object object) {
		Map<String, Invoke> map = new HashMap<>();
		Class<?> findClass = object.getClass();
		   Method[] ms = findClass.getMethods();  
           for (Method method : ms) {  
        	   //url 注解
        	   Invoke invoke = new Invoke();
              boolean annotationPresent = method.isAnnotationPresent(RequesUrl.class);
              if(annotationPresent) {//包含注解
            	  RequesUrl requesUrl = method.getAnnotation(RequesUrl.class); 
            	  invoke.setMethod(method.getName());
            	  invoke.setSeviceObject(object);
            	  invoke.setParamTypes(method.getParameterTypes());
            	  invoke.setParam(method.getParameters());
            	  map.put(requesUrl.value(), invoke);
              }
              	//json 或者视图解析
              boolean view = method.isAnnotationPresent(View.class);
              if(view){
            	  View annotation = method.getAnnotation(View.class);
            	  invoke.setModeView(new ModeView(annotation.value()));
              }
           }  
		return map;
	}

}
